import Ember from 'ember';
import config from 'game-front/config/environment';
import RSVP from 'rsvp';

export default Ember.Route.extend({
	share:Ember.inject.service(),
	game:Ember.inject.service(),
	model(params) {
		const userInfo = this.modelFor("application");
		console.log(params);
		return RSVP.hash({
			userInfo: userInfo,
			isFirstTime: Ember.$.getJSON(config.apiBase + "members/played", {userId: userInfo.userId, gameZoneProductId:params.game_id}),
			gameInfo:this.get("game").getGameById(params.game_id)
		});
	},
	afterModel: function(model) {
		console.log(model);
		const userId = sessionStorage.getItem("userId");
		const shareLink = {
			title: `90秒夺宝-${model.gameInfo.productName}`, // 分享标题
			desc: model.gameInfo.gameZoneProductId === 1 ? '这是一款神奇的游戏，轻松一棒就可轻松赢取大奖' : 'pm2.5越来越浓烈，看谁能坚到拨云见奖的一天',
			link: `${window.location.origin}${config.baseURL}gameshare/${model.gameInfo.gameZoneProductId}?public=true&key=${userId}`, // 分享链接
			imgUrl: 'http://game.inkanke.com/yydb/assets/images/banner.png', // 分享图标
			success: function () {
				share.reward(userId);
				// 生成推荐二维码
				share.createQR(userId);
			},
			cancel: function () {
				// 用户取消分享后执行的回调函数
			}
		};
		const share = this.get("share");
		share.config(shareLink);
	},
	actions:{
		home () {
			if (parseInt($(".user-prise").text()) < 2 ){
				$(".shade").css({"display":"block"});
				$(".div-shade").css({"display":"block"});
			}else {
				$(".shade").css({"display":"block"});
				$(".div-shade-teo").css({"display":"block"});
			}
		},nohover() {
			$(".shade").css({"display":"none"});
			$(".div-shade").css({"display":"none"});
		}
	}
});
